//
//  LoginAgreementView.m
//  Project_IOS
//
//  Created by topnet on 2022/4/6.
//

#import "LoginAgreementView.h"
#import "YYText.h"
#import "WKWebVC.h"
#import "Color.h"
#import <Masonry/Masonry.h>
@interface LoginAgreementView ()

@property (nonatomic, strong)YYLabel *lbl;
@end

@implementation LoginAgreementView

- (instancetype)init {
    if (self = [super init]) {
        [self addSubview:self.btn];
        [self addSubview:self.lbl];
        [self setText];
    }
    return self;
}

- (void)setText {
//    MJWeakSelf
    NSMutableAttributedString *t1 = [[NSMutableAttributedString alloc] initWithString:@"登录即同意"];
    t1.yy_color = UIColor.lightGrayColor;
    NSMutableAttributedString *t2 = [[NSMutableAttributedString alloc] initWithString:@"《用户协议》"];
    t2.yy_color = [UIColor blueColor];
    [t2 yy_setTextHighlightRange:t2.yy_rangeOfAll color:[UIColor blueColor] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        NSLog(@"用户协议");
//        [weakSelf goAgreement:NO];
    }];
    NSMutableAttributedString *t3 = [[NSMutableAttributedString alloc] initWithString:@"和"];
    t3.yy_color = UIColor.blackColor;
    NSMutableAttributedString *t4 = [[NSMutableAttributedString alloc] initWithString:@"《隐私政策》"];
    t4.yy_color = [UIColor blueColor];
    [t4 yy_setTextHighlightRange:t2.yy_rangeOfAll color:[UIColor blueColor] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        NSLog(@"隐私政策");
//        [weakSelf goAgreement:YES];
    }];
    [t1 appendAttributedString:t2];
    [t1 appendAttributedString:t3];
    [t1 appendAttributedString:t4];
    t1.yy_font = [UIFont systemFontOfSize:11];
    self.lbl.attributedText = t1;
}
//http://meme-labs.com/apps/cloudalbum/AccountAggrement.html
//http://meme-labs.com/apps/cloudalbum/PrivatePolicy.html
//http://meme-labs.com/apps/cloudalbum/UserServiceAgreement.html
- (void)goAgreement:(BOOL)isPrivary {
    WKWebVC *vc = [WKWebVC new];
    vc.navTitle = isPrivary ? @"隐私政策" : @"用户协议";
    vc.urlStr = isPrivary ? @"http://meme-labs.com/apps/cloudalbum/PrivatePolicy.html" : @"http://meme-labs.com/apps/cloudalbum/UserServiceAgreement.html";
//    [self.viewControll.navigationController pushViewController:vc animated:YES];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(self.mas_height);
        make.top.left.equalTo(@0);
    }];
    [self.lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.btn.mas_right);
        make.centerY.right.equalTo(@0);
    }];
}

- (void)btnClick {
    self.btn.selected = !self.btn.isSelected;
}

- (YYLabel *)lbl {
    if (!_lbl) {
        _lbl = [YYLabel new];
    }
    return _lbl;
}

- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn setImage:[UIImage imageNamed:@"check_y"] forState:UIControlStateSelected];
        [_btn setImage:[UIImage imageNamed:@"check_n"] forState:UIControlStateNormal];
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
